package com.jxlg.action;

import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.util.List;

import org.hibernate.Transaction;

import com.jxlg.bean.WCarinfo;
import com.jxlg.dao.DDictinfoDAO;
import com.jxlg.dao.WCarinfoDAO;
import com.jxlg.util.HibernateSessionFactory;

public class CarinfoAction extends BaseAction
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -610539663734083771L;
	/**
	 * 跳转到入场登记页面
	 */
	/**
	 * XMXH -> 项目序号 HPZL -> 号牌种类 ZKLX -> 暂扣类型 ZKYY -> 暂扣原因 CLLX -> 车辆类型
	 */

	private static final int HPZL_XMXH = 3;
	private static final int ZKLX_XMXH = 1;
	private static final int CLLX_XMXH = 4;
	private static final int ZKYY_XMXH = 5;

	private List<?> hpzlList; // 号牌种类列表
	private List<?> zklxList; // 暂扣类型列表
	private List<?> cllxList; // 车辆类型列表
	private List<?> zkyyList; // 暂扣类型列表
	private int hpzl; // 号牌种类
	private String zklx; // 暂扣类型
	private String cllx; // 车辆类型
	private int zkyy; // 暂扣类型
	private int djh; // 登记号
	private String rcsj; // 赞扣时间
	private String dsrxm; // 当事人姓名
	private String dsrsfz; // 当事人身份证
	private String tbsj; // 填表时间
	private String zrczyxm; // 转入车场操作员姓名
	private String czxm; // 车主姓名
	private String czsfz; // 车主身份证
	private String sm; // 备注内容

	// -----------------------卖萌的分割线-----------------------------

	public int getHpzl()
	{
		return hpzl;
	}

	public void setHpzl(int hpzl)
	{
		this.hpzl = hpzl;
	}

	public List<?> getHpzlList()
	{
		return hpzlList;
	}

	public void setHpzlList(List<?> hpzlList)
	{
		this.hpzlList = hpzlList;
	}

	public List<?> getZklxList()
	{
		return zklxList;
	}

	public void setZklxList(List<?> zklxList)
	{
		this.zklxList = zklxList;
	}

	public List<?> getCllxList()
	{
		return cllxList;
	}

	public void setCllxList(List<?> cllxList)
	{
		this.cllxList = cllxList;
	}

	public List<?> getZkyyList()
	{
		return zkyyList;
	}

	public void setZkyyList(List<?> zkyyList)
	{
		this.zkyyList = zkyyList;
	}

	public String getZklx()
	{
		return zklx;
	}

	public void setZklx(String zklx)
	{
		this.zklx = zklx;
	}

	public String getCllx()
	{
		return cllx;
	}

	public void setCllx(String cllx)
	{
		this.cllx = cllx;
	}

	public int getZkyy()
	{
		return zkyy;
	}

	public void setZkyy(int zkyy)
	{
		this.zkyy = zkyy;
	}

	public int getDjh()
	{
		return djh;
	}

	public void setDjh(int djh)
	{
		this.djh = djh;
	}

	public String getRcsj()
	{
		return rcsj;
	}

	public void setRcsj(String rcsj)
	{
		this.rcsj = rcsj;
	}

	public String getDsrxm()
	{
		return dsrxm;
	}

	public void setDsrxm(String dsrxm)
	{
		this.dsrxm = dsrxm;
	}

	public String getDsrsfz()
	{
		return dsrsfz;
	}

	public void setDsrsfz(String dsrsfz)
	{
		this.dsrsfz = dsrsfz;
	}

	public String getTbsj()
	{
		return tbsj;
	}

	public void setTbsj(String tbsj)
	{
		this.tbsj = tbsj;
	}

	public String getZrczyxm()
	{
		return zrczyxm;
	}

	public void setZrczyxm(String zrczyxm)
	{
		this.zrczyxm = zrczyxm;
	}

	public String getCzxm()
	{
		return czxm;
	}

	public void setCzxm(String czxm)
	{
		this.czxm = czxm;
	}

	public String getCzsfz()
	{
		return czsfz;
	}

	public void setCzsfz(String czsfz)
	{
		this.czsfz = czsfz;
	}
	
	public String getSm()
	{
		return sm;
	}

	public void setSm(String sm)
	{
		this.sm = sm;
	}

	// -----------------------卖萌的分割线----------------------------- \\\\\
	/**
	 * 向 setCarinfo.jsp 写入数据有hpzlList,zklxList,cllxList,zkyyList,djh
	 * 
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public String doAddSelectList() throws UnsupportedEncodingException
	{
		// 获取页面下拉框所需要的数据
		Transaction tr = HibernateSessionFactory.getSession()
				.beginTransaction();
		DDictinfoDAO dictinfoDAO = new DDictinfoDAO();
		this.hpzlList = dictinfoDAO
				.getDictinfoListByXMXH(CarinfoAction.HPZL_XMXH);
		this.zklxList = dictinfoDAO
				.getDictinfoListByXMXH(CarinfoAction.ZKLX_XMXH);
		this.cllxList = dictinfoDAO
				.getDictinfoListByXMXH(CarinfoAction.CLLX_XMXH);
		this.zkyyList = dictinfoDAO
				.getDictinfoListByXMXH(CarinfoAction.ZKYY_XMXH);
		tr.commit();
		/** debug */
		System.out.println("号牌种类.size() = " + hpzlList.size());
		System.out.println("暂扣类型.size() = " + zklxList.size());
		System.out.println("暂扣原因.size() = " + zkyyList.size());
		System.out.println("车辆类型.size() = " + cllxList.size());

		/** debug \ */
		this.djh = com.jxlg.dao.WCarinfoDAO.doAddEmptyItem();
		return "doAdd";
	}

	/**
	 * doSaveCarinfo
	 * 
	 * 把入场登入信息保存在数据库中去。
	 * 
	 * @return
	 */
	public String doSaveCarinfo()
	{
		System.out.println("------------------------------");
		System.out.println("登记号:" + this.djh);
		System.out.println("车辆类型:" + this.cllx);
		System.out.println("号牌种类" + this.hpzl);
		System.out.println("赞扣类型:" + this.zklx);
		System.out.println("入场时间:" + this.rcsj);
		System.out.println("当事人姓名:" + this.dsrxm);
		System.out.println("当事人身份证:" + this.dsrsfz);
		System.out.println("车主姓名:" + this.czxm);
		System.out.println("车主身份证:" + this.czsfz);
		System.out.println("转入车场操作员姓名:" + this.zrczyxm);
		System.out.println("填表时间:" + this.tbsj);
		System.out.println("备注内容:" + this.sm);
		

		/**
		 * set carinfo
		 */
		WCarinfo carinfo = new WCarinfo();
		carinfo.setCllx(this.cllx);
		carinfo.setTzid(this.djh);
		carinfo.setZklx(this.zklx);
		// carinfo.setZksj(Timestamp.valueOf(this.rcsj));
		carinfo.setZksj(new Timestamp(System.currentTimeMillis()));
		carinfo.setDsrxm(this.dsrxm);
		carinfo.setDsrsfz(this.dsrsfz);
		carinfo.setTbsj(Timestamp.valueOf(this.tbsj));
		carinfo.setZrczyxm(this.zrczyxm);
		carinfo.setCzxm(this.czxm);
		carinfo.setCzsfz(this.czsfz);
		carinfo.setRcfs(0); // 入场方式设置为正常入场方式
		carinfo.setSm(this.sm);// 去你吗的备注，，其实是说明啊。
		
		WCarinfoDAO carinfoDAO = new WCarinfoDAO();
		Transaction tr = HibernateSessionFactory.getSession()
				.beginTransaction();
		tr.begin();
		// carinfoDAO.save(carinfo); // 去他妹的添加啊，关你save什么事？应该是add啊
		carinfoDAO.merge(carinfo); // 去你妈的修改啊，
		tr.commit();
		return "success";
	}
}
